<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow-y:auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理后台</title>
<link rel="stylesheet" href="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/css/admin.css";?>" />
<script charset="UTF-8" src="/runtime/systemjs/jquery-1.4.4.min.js"></script>
<script charset="UTF-8" src="/runtime/systemjs/artdialog/artDialog.min.js"></script>
<script charset="UTF-8" src="/runtime/systemjs/form.js"></script>
<link rel="stylesheet" type="text/css" href="/runtime/systemjs/autovalidate/style.css"/><script charset="UTF-8" src="/runtime/systemjs/autovalidate/validate.js"></script>
<script type='text/javascript' src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/javascript/admin.js";?>"></script>
<script type='text/javascript' src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/javascript/menu.js";?>"></script>
</head>
<body style="width:750px">
<div class="pop_win">
<form action="<?php echo IUrl::creatUrl("/order/order_delivery_doc");?>" method="post" id="deliver_form">
	<table width="90%" class="border_table" style="margin:10px auto">
		<col width="100px" />
		<col />
		<col width="100px" />
		<col />
		<tbody>
			<tr>
				<th>订单号:</th><td align="left"><?php echo isset($order_no)?$order_no:"";?><input type="hidden" name="order_no" value="<?php echo isset($order_no)?$order_no:"";?>"/></td><th>下单时间:</th><td align="left"><?php echo isset($create_time)?$create_time:"";?></td>
			</tr>
			<tr><input type="hidden" name="id" id="id" value="<?php echo isset($order_id)?$order_id:"";?>"/><input type="hidden" name="weight_total" id="weight_total" value="<?php echo isset($goods_weight)?$goods_weight:"";?>"/>
				<th>配送方式:</th><td align="left"><input type="hidden" name="user_id" id="user_id" value="<?php echo isset($user_id)?$user_id:"";?>"/>
				<select name="delivery_type" id="delivery_type" onchange="order_delivery(this.value)" pattern="required" alt="请选择配送方式">
					<?php $query = new IQuery("delivery");$query->where = "is_delete = 0";$items = $query->find(); foreach($items as $key => $item){?>
						<option value="<?php echo isset($item['id'])?$item['id']:"";?>" <?php if($distribution==$item['id']){?>selected<?php }?>><?php echo isset($item['name'])?$item['name']:"";?></option>
					<?php }?>
					</select></td><th>配送费用:</th><td align="left"><input type="text" id="freight" name="freight" value="<?php echo isset($real_freight)?$real_freight:"";?>"/></td>
			</tr>
			<tr>
				<th>配送单号:</th><td align="left" colspan="3"><input type="text" name="delivery_code" id="delivery_code"/></td>
			</tr>
			<tr>
				<th>是否保价:</th><td align="left"><?php if($if_insured==0){?>否<?php }else{?>是<?php }?></td><th>保价费用:</th><td align="left">￥<?php echo isset($insured)?$insured:"";?></td>
			</tr>
			<tr>
				<th>收货人姓名:</th><td align="left"><input type="text" name="name" id="name" value="<?php echo isset($accept_name)?$accept_name:"";?>"/></td><th>电话:</th><td align="left"><input type="text" name="telphone" id="telphone" value="<?php echo isset($telphone)?$telphone:"";?>"/></td>
			</tr>
			<tr>
				<th>手机:</th><td align="left"><input type="text" name="mobile" id="mobile" value="<?php echo isset($mobile)?$mobile:"";?>"/></td><th>邮政编码:</th><td align="left"><input type="text" name="postcode" id="postcode" value="<?php echo isset($postcode)?$postcode:"";?>"/></td>
			</tr>
			<tr>
				<th>地区:</th>
				<td align="left" colspan="3"><select name="province" id="province" onchange="select_city(this.value,2);">
							<option value="">请选择省份</option>
							<?php $query = new IQuery("areas");$query->where = "parent_id = 0";$items = $query->find(); foreach($items as $key => $item){?><option value="<?php echo isset($item['area_id'])?$item['area_id']:"";?>" <?php if($province==$item['area_id']){?>selected<?php }?>><?php echo isset($item['area_name'])?$item['area_name']:"";?></option><?php }?>
							</select>
							<span id="selec2"></span><span id="selec3"></span>
				</td>
			</tr>
			<tr>
				<th>地址:</th><td align="left" colspan="3"><input type="text" name="address" id="address" value="<?php echo isset($address)?$address:"";?>" size="50"/></td>
			</tr>
			<tr>
				<th>发货单备注:</th><td align="left" colspan="3"><textarea name="note" id="note" rows="3" cols="45"> </textarea></td>
			</tr>
		</tbody>
	</table>
	<table width="90%" class="border_table" style="margin:10px auto">
		<col />
		<col width="80px" />
		<col width="80px" />
		<col width="80px" />
		<col width="80px" />
		<col width="130px" />
		<thead>
			<tr><th>商品名称</th><th>商品价格</th><th>当前库存</th><th>购买数量</th><th>已发货</th><th>此单发货</th></tr>
		</thead>
		<tbody>
			<?php $ogid=''?>
			<?php $query = new IQuery("order_goods as og");$query->join = "left join goods as gg on og.goods_id = gg.id left join products as p on p.id = og.product_id";$query->fields = "gg.name as gname,p.spec_array as spec,og.id as ogid,og.product_id,og.goods_array,og.goods_price,og.goods_nums,og.real_price*og.goods_nums as total,og.real_price,og.shipments,gg.store_nums";$query->where = "og.order_id = $order_id";$items = $query->find(); foreach($items as $key => $item){?>
				<?php $ogid .=$item['ogid'].',';?>
				<tr>
					<td style="white-space:normal">
						<?php echo isset($item['gname'])?$item['gname']:"";?>&nbsp;&nbsp;
						<?php if($item['spec']){?>
						<?php $arr = unserialize($item['spec']);?>
						<?php foreach($arr as $key => $cc){?>
							<?php $query = new IQuery("spec");$query->fields = "name,type";$query->where = "id = $cc[id]";$items = $query->find(); foreach($items as $key => $va){?>
								<?php echo $va['name'];?>:<?php if($va['type']==1){?><?php echo isset($cc['value'])?$cc['value']:"";?><?php }else{?><img src="<?php echo IUrl::creatUrl().$cc['value'];?>" width="15px" height="15px" /><?php }?>&nbsp;&nbsp;
							<?php }?>
						<?php }?>
						<?php }?>
					</td>
					<td><?php echo isset($item['real_price'])?$item['real_price']:"";?></td>
					<td><?php echo isset($item['store_nums'])?$item['store_nums']:"";?></td>
					<td><?php echo isset($item['goods_nums'])?$item['goods_nums']:"";?></td>
					<td><?php echo isset($item['shipments'])?$item['shipments']:"";?></td>
					<td><?php echo isset($item['goods_nums'])?$item['goods_nums']:"";?></td>
				</tr>
			<?php }?>
			<input type="hidden" name="ogid" id="ogid" value="<?php echo isset($ogid)?$ogid:"";?>" />
		</tbody>
	</table>
</form>
</div>
<script type="text/javascript">
var province_va = '';
var city_va = '';
var area_va = '';
<?php if($province!=''){?>
province_va = '<?php echo isset($province)?$province:"";?>';
city_va = '<?php echo isset($city)?$city:"";?>';
area_va = '<?php echo isset($area)?$area:"";?>';
<?php }?>
if(city_va!='')
{
	select_city(province_va,'2');
}
if(area_va!='')
{
	select_city(city_va,'3');
}
function select_city(city,style)
{
	$.getJSON("<?php echo IUrl::creatUrl("/block/area_child");?>",{aid:city}, function(json)
	{
		if(style==2)
		{
			var select_html = '<select name="city" id="city" onchange="select_city(this.value,3);">';
			select_html += '<option value="">请选择城市</option>';
			for( a in json)
			{
				if(json[a]['area_id']==city_va)
				{
					select_html +='<option value="'+json[a]['area_id']+','+json[a]['area_name']+'" selected>'+json[a]['area_name']+'</option>';
				}
				else
				{
					select_html +='<option value="'+json[a]['area_id']+','+json[a]['area_name']+'">'+json[a]['area_name']+'</option>';
				}
			}
			select_html +='</select>';
			if($("#selec3").text()=='')$("#selec3").hide();
			$("#selec"+2).html(select_html);
		}
		if(style==3)
		{
			if(json.length>0)
			{
				var select_html = '<select name="area" id="area" onchange="select_city(this.value,4);">';
				select_html += '<option value="">请选择地区</option>';
				for( a in json)
				{
					if(json[a]['area_id']==area_va)
					{
						select_html +='<option value="'+json[a]['area_id']+','+json[a]['area_name']+'" selected>'+json[a]['area_name']+'</option>';
						if(area_va!='')
						{
							select_city(area_va,4);
						}
					}
					else
					{
						select_html +='<option value="'+json[a]['area_id']+','+json[a]['area_name']+'">'+json[a]['area_name']+'</option>';
					}
				}
				select_html +='</select>';
				$("#selec3").show();
				$("#selec3").html(select_html);
			}
			else
			{
				if($("#selec3").text()=='')$("#selec3").hide();
			}
		}
	});
}
function order_delivery(va)
{
	var weight = $("#weight_total").val();
	var province = $("#province").val();
	$.getJSON("<?php echo IUrl::creatUrl("/block/order_delivery");?>",
	{province:province,weight:weight},
	function(json){
		var html_va = '<option value="">请选择</option>';
		var price = 0;
		for( a in json)
		{
			if(json[a]['id']==va)
			{
				html_va += '<option value="'+json[a]['id']+'" selected>'+json[a]['name']+'</option>';
				price = json[a]['price'];
			}
			else
			{
				html_va += '<option value="'+json[a]['id']+'">'+json[a]['name']+'</option>';
			}
		}
		$('#freight').val(price);
	});
}
</script>
</body>
</html>